<div class="layui-fluid layui-anim febs-anim" id="febs-income" lay-title="收入管理">
    <div class="layui-row febs-container">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body febs-table-full">
                    <form class="layui-form layui-table-form" lay-filter="income-table-form">
                        <div class="layui-row">
<!--                            <div class="layui-col-md10">-->
<!--                                <div class="layui-form-item">-->
<!--                                    <div class="layui-inline">-->
<!--                                        <label class="layui-form-label layui-form-label-sm">活动名称</label>-->
<!--                                        <div class="layui-input-inline">-->
<!--                                            <input type="text" name="activityName" autocomplete="off"-->
<!--                                                   placeholder="输入活动名称进行检索" class="layui-input">-->
<!--                                        </div>-->
<!--                                    </div>-->
<!--                                </div>-->
<!--&lt;!&ndash;                                <div class="layui-form-item">&ndash;&gt;-->
<!--&lt;!&ndash;                                    <div class="layui-inline">&ndash;&gt;-->
<!--&lt;!&ndash;                                        <label class="layui-form-label layui-form-label-sm">客户名称</label>&ndash;&gt;-->
<!--&lt;!&ndash;                                        <div class="layui-input-inline">&ndash;&gt;-->
<!--&lt;!&ndash;                                            <input type="text" name="nickName" autocomplete="off"&ndash;&gt;-->
<!--&lt;!&ndash;                                                   placeholder="输入活动名称进行检索" class="layui-input">&ndash;&gt;-->
<!--&lt;!&ndash;                                        </div>&ndash;&gt;-->
<!--&lt;!&ndash;                                    </div>&ndash;&gt;-->
<!--&lt;!&ndash;                                </div>&ndash;&gt;-->
<!--                            </div>-->
<!--                            <div class="layui-col-md2 layui-col-sm12 layui-col-xs12 table-action-area">-->
<!--                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="query">-->
<!--                                    <i class="layui-icon">&#xe848;</i>搜索-->
<!--                                </div>-->
<!--                                <div class="layui-btn layui-btn-sm layui-btn-primary table-action" id="reset">-->
<!--                                    <i class="layui-icon">&#xe79b;</i>刷新-->
<!--                                </div>-->
<!--                            </div>-->
                        </div>
                    </form>
                    <table lay-filter="incomeTable" lay-data="{id: 'incomeTable'}"></table>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/html" id="user-status">
    {{#
    var status = {
    1: {title: '有效', color: 'green'},
    0: {title: '禁用', color: 'red'}
    }[d.status];
    }}
    <span class="layui-badge febs-tag-{{status.color}}">{{ status.title }}</span>
</script>
<script type="text/html" id="user-sex">
    {{#
    var sex = {
    2: {title: '保密'},
    1: {title: '女'},
    0: {title: '男'}
    }[d.sex];
    }}
    <span>{{ sex.title }}</span>
</script>
<script type="text/html" id="income-option">
    <span shiro:lacksPermission="income:view">
        <span class="layui-badge-dot febs-bg-orange"></span> 无权限
    </span>
    <a lay-event="incomeEdit" shiro:hasPermission="income:update"><i
            class="layui-icon febs-edit-area febs-bg-red">&#xe7a4;</i>提现</a>
</script>
<script data-th-inline="javascript" type="text/javascript">
    layui.use(['dropdown', 'jquery', 'upload', 'laydate', 'form', 'formSelects', 'table', 'febs'], function () {
        var $ = layui.jquery,
            febs = layui.febs,
            form = layui.form,
            table = layui.table,
            $view = $('#febs-income'),
            customerId = [[${customerId}]],
            $query = $view.find('#query'),
            $reset = $view.find('#reset'),
            $searchForm = $view.find('form'),
            sortObject = {field: 'createTime', type: null},
            tableIns,
            createTimeFrom,
            createTimeTo;
        form.render();

        initTable();

        table.on('tool(incomeTable)', function (obj) {
            var data = obj.data,
                layEvent = obj.event;

            if (layEvent === 'incomeEdit') {
                febs.modal.open('修改收入', 'system/income/update/' + data.incomeId, {
                    area: ['50%', '70%'],
                    btn: ['提交', '取消'],
                    yes: function (index, layero) {
                        $('#income-update-form').find('#submit').trigger('click');
                    },
                    btn2: function () {
                        layer.closeAll();
                    }
                });
            }
        });

        table.on('sort(incomeTable)', function (obj) {
            sortObject = obj;
            tableIns.reload({
                initSort: obj,
                where: $.extend(getQueryParams(), {
                    field: obj.field,
                    order: obj.type
                })
            });
        });

        $query.on('click', function () {
            var params = $.extend(getQueryParams(), {field: sortObject.field, order: sortObject.type});
            tableIns.reload({where: params, page: {curr: 1}});
        });

        $reset.on('click', function () {
            $searchForm[0].reset();
            sortObject.type = 'null';
            createTimeTo = null;
            createTimeFrom = null;
            tableIns.reload({where: getQueryParams(),  initSort: sortObject,
                done: function(res, curr, count){
                    //如果是异步请求数据方式，res即为你接口返回的信息。
                    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                    //得到当前页码
                    //得到数据总量
                    var beforeCurr = curr;
                    //当前页数据的个数
                    var dataLength = res.data.length;
                    var count = res.count;
                    //如果当前页数据的个数等于0，并且总数不为0，则跳转到上一页
                    if( dataLength == 0 && count!= 0 ){
                        table.reload("incomeTable",{
                            page:{curr:beforeCurr - 1}
                        })
                    }
                }
            });
        });

        function initTable() {
            tableIns = febs.table.init({
                elem: $view.find('table'),
                id: 'userTable',
                url: ctx + 'income/getIncomeList?customerId='+customerId,
                cols: [[
                    {type: 'checkbox'},
                    {field: 'nickName', title: '用户昵称'},
                    {field: 'headImgUrl', title: '用户头像', templet: function (d) {
                            if (d.headImgUrl!=null) {
                                return '<img style="width: 200px;height:160px"  src="' + d.headImgUrl + '">'
                            }else {
                                return '';
                            }
                        }},
                    // {field: 'activityName', title: '活动名称'},
                    // {field: 'headPhoto', title: '活动头图', templet: function (d) {
                    //         if (d.headPhoto!=null) {
                    //             return '<img style="width: 200px;height:160px"  src="' + d.headPhoto + '">'
                    //         }else {
                    //             return '';
                    //         }
                    //     }},
                    {field: 'incomePrice', title: '交易金额',templet:function (d){
                        if (d.status==0){
                            return '<div style="color: red">提现：'+d.incomePrice+'</div>';
                        }else {
                            return '<div style="color: green">收入：'+d.incomePrice+'</div>';
                        }
                        }},
                    {field: 'createTime', title: '时间' ,templet:function (d) {
                            if (d.createTime != null){
                                return layui.util.toDateString(d.createTime, 'yyyy年MM月dd日 HH:mm:ss')
                            }else{
                                return ''
                            }
                        }},
                    // {title: '操作', toolbar: '#income-option',align:"center", minWidth: 200}
                    // {field: 'createTime', title: '创建时间' },
                ]]
            });
        }

        function getQueryParams() {
            return {
                activityName: $searchForm.find("input[name='activityName']").val(),
                nickName: $searchForm.find("input[name='nickName']").val(),
                invalidate_ie_cache: new Date()
            };
        }

        // function deleteUsers(customerIds) {
        //     febs.get(ctx + 'order/delete/' + orderIds, null, function () {
        //         febs.alert.success('删除订单成功');
        //         $reset.click();
        //     });
        // }
    })
</script>